package com.dyw.spzx.manager.controller;

import com.dyw.spzx.manager.service.SysRoleService;
import com.dyw.spzx.model.dto.system.SysRoleDto;
import com.dyw.spzx.model.entity.system.SysRole;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "角色接口")
@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @Operation(summary = "获取角色列表")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(@PathVariable("pageNum") Integer pageNum,
                                                @PathVariable("pageSize") Integer pageSize, SysRoleDto sysRoleDto
    ) {
        PageInfo<SysRole> sysRolePageInfo = sysRoleService.findByPage(pageNum, pageSize, sysRoleDto);

        return Result.ok(sysRolePageInfo);
    }

    @Operation(summary = "添加角色")
    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.ok(null);
    }

    @Operation(summary = "修改角色")
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.ok(null);
    }

    @Operation(summary = "删除角色信息")
    @DeleteMapping("/deleteById/{roleId}")
    public Result deleteById(@PathVariable("roleId") Integer roleId) {
        sysRoleService.deleteRoleById(roleId);
        return Result.ok(null);
    }

    @Operation(summary = "查询所有角色信息")
    @GetMapping("/findAllRoles/{userId}")
    public Result<Map<String, Object>> findAllRoles(@PathVariable("userId") Long userId) {
        Map<String,Object> resultMap = sysRoleService.findAllRoles(userId);
        return Result.ok(resultMap);
    }






}
